package com.lsa.skienna.challenge.chap6;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Scanner;

public class Fibs implements Runnable{
	
	private static final int roundingMode = BigDecimal.ROUND_HALF_DOWN;
	private static final BigDecimal SQRT_5 = create("2.2360679774997896964091736687313");
	
	private static final int precision = 100;
	private static final int largestFibN = 481;
	private static int[] firstFibs = new int[]{0,1,1,2,3,5,8,13,21,34,55};
	
	public static void main(String[] args) throws IOException {
		new Fibs().run();
	}
	
	static class TaskReader{
		private BufferedReader reader;
		
		TaskReader(InputStream stream) {
			this.reader = new BufferedReader(new InputStreamReader(stream));
		}
		
		BigDecimal[] readNextTask() throws IOException{
			BigDecimal[] task = null;
			
			String line = reader.readLine();
			if (line == null){
				return null;
			}
			
			Scanner scanner = new Scanner(line);
			int n = 2;
			
			try{
				task = new BigDecimal[n];
				
				for(int i = 0; i < n; ++i){
					task[i] = scanner.nextBigDecimal();
					if (i == 0 ) scanner.skip(" ");
				}
			}
			catch(RuntimeException e){
				return null;
			}
			
			
			return task;
		}
	}
	
	static class ResultWriter{
		private static final String lineSeparator = System.getProperty("line.separator");
		
		private BufferedWriter writer;
		ResultWriter(OutputStream stream) {
			this.writer = new BufferedWriter(new OutputStreamWriter(stream));
		}
		
		void write(int count) throws IOException{
			writer.write(""+count);
			writer.write(lineSeparator);
			writer.flush();
		}
	}
	
	@Override
	public void run() {
		try {
			TaskReader taskReader = new TaskReader(System.in);
			ResultWriter resultWriter = new ResultWriter(System.out);
			BigDecimal[] task;
			while((task = taskReader.readNextTask())!= null){
				if (task[0].equals(BigDecimal.ZERO) && task[1].equals(BigDecimal.ZERO)) break;
				resultWriter.write(count(task));
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	static int count(BigDecimal[] task) {
		return count(task[0], task[1]);
	}
	
	 private static int count(BigDecimal leftBound, BigDecimal rightBound){
		int firstN = findFirstGreaterOrEqualThen(leftBound);
		int lastN = findLastLessOrEqualThen(rightBound);
		return lastN - firstN + 1;
	}
	
	private static int findLastLessOrEqualThen(BigDecimal rightBound) {
		int leftN = 2;
		int rightN = largestFibN;
		
		BigDecimal rightEst = estimate(rightN);
		if (rightEst.subtract(rightBound).abs().compareTo(BigDecimal.ZERO) == 0) return rightN;
		
		BigDecimal prev = BigDecimal.ONE.negate();
		while( true ){
			int curN = (leftN + rightN) / 2;
			BigDecimal cur = estimate(curN);
			if (cur.subtract(rightBound).abs().compareTo(new BigDecimal("0.5")) < 0){
				leftN = curN;
				break;
			}
				
			int cmp = cur.compareTo(rightBound);
			if (cmp > 0) {
				rightN = curN;
			} else if (cmp < 0) {
				leftN = curN;
			} 
			else { // low probability
				leftN = curN;
				break;
			}
			
			if (cur.compareTo(prev) == 0) break;
			prev = cur;
		}
		
		return leftN;
	}
	
	private static int findFirstGreaterOrEqualThen(BigDecimal leftBound) {
		int leftN = 2;
		int rightN = largestFibN;
		
		BigDecimal leftEst = estimate(leftN);
		if (leftEst.subtract(leftBound).abs().compareTo(BigDecimal.ZERO) == 0) return leftN;
		
		BigDecimal prev = BigDecimal.ONE.negate();
		while( true ){
			int curN = (leftN + rightN) / 2;
			BigDecimal cur = estimate(curN);
			if (cur.subtract(leftBound).abs().compareTo(new BigDecimal("0.5")) < 0){
				rightN = curN;
				break;
			}
			int cmp = cur.compareTo(leftBound);
			if (cmp > 0) {
				rightN = curN;
			} else if (cmp < 0) {
				leftN = curN;
			} else { // low probability
				rightN = curN;
				break;
			}
			if (cur.compareTo(prev) == 0) break;
			prev = cur;
		}
		
		return rightN;
	}
	
	static BigDecimal create(String val, int prec){
		MathContext mc = new MathContext(prec/*, roundingMode*/);
		return new BigDecimal(val, mc);
	}
	
	static BigDecimal create(String val){
		return create(val, precision);
	}
	
//	static BigDecimal estimate(int n){
//		BigDecimal res = create("1").add(SQRT_5);
//		BigDecimal two = create("2");
//		res = res.divide(two, precision, roundingMode);
//		res = res.pow(n);
//		return res.divide(SQRT_5, precision, roundingMode);
//	}
	
	private static BigDecimal isqrt(BigDecimal x, MathContext mc) {
	     BigDecimal guess = new BigDecimal(1/Math.sqrt(x.doubleValue()));
	     BigDecimal three = new BigDecimal(3);
	     BigDecimal half = new BigDecimal(0.5);
	     BigDecimal oldguess;
	     do{ oldguess = guess;
	         guess = half.multiply(guess.multiply(
	                   three.subtract(x.multiply(guess.pow(2)))), mc);
	     } while (oldguess.compareTo(guess) != 0);
	     
	     return guess;
	 }
	
	private static BigDecimal estimate(int n) {
		if (n < firstFibs.length) return new BigDecimal(firstFibs[n]);
	    MathContext mc = new MathContext(n/2, RoundingMode.HALF_DOWN);
	    BigDecimal is5 = isqrt(new BigDecimal("5"), mc);
	    BigDecimal one = BigDecimal.ONE;
	    BigDecimal half = new BigDecimal(0.5);
	    BigDecimal phi = half.multiply(one.add(one.divide(is5, mc)));
	    return phi.pow(n, mc).multiply(is5);
	 }
}
